package com.ecds.monitor.helper;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import com.ecds.monitor.MainServer;

public class ConnUtil {
	public static Connection getConn() {
		Connection conn = null;
		try {
			String url = MainServer.rb.getString("monitoring.data");
			String username = MainServer.rb.getString("monitoring.data.username");
			String password = MainServer.rb.getString("monitoring.data.password");
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			try {
				conn = DriverManager.getConnection(url, username, password);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return conn;
	}
	
	public static void closeConn(Statement sta, PreparedStatement pst, Connection conn){
		try {
			if(sta != null){
				sta.close();
			}
			if(pst != null){
				pst.close();
			}
			if(conn != null){
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
